package com.dhl.rabbitmq.six;

import com.dhl.rabbitmq.utils.RabbitUtils;
import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.MessageProperties;

import java.nio.charset.StandardCharsets;

/**
 * @author danghailiang
 */
public class EmitDirectLog {
    public static final String EXCHANGE_NAME = "direct_log";

    public static void main(String[] args) throws Exception {
        // 1.获取信道
        Channel channel = RabbitUtils.getChannel();
        // 2.获取交换
        channel.exchangeDeclare(EXCHANGE_NAME, BuiltinExchangeType.DIRECT);
        int i = 0;
        while(i<100){
            String routing = "";
            if(i%3==0){
                routing = "error";
            } else if (i%3==1) {
                 routing = "info";
            } else {
                 routing = "warning";
            }
            // 3.发送信息
            String message  = routing + i;;
            channel.basicPublish(EXCHANGE_NAME,routing, MessageProperties.PERSISTENT_TEXT_PLAIN,message.getBytes(StandardCharsets.UTF_8));
            i++;
        }
    }
}
